<?php

/**
 * Class own_shopControl
 * 自选商品
 */

  Class own_shopControl extends mobileMemberControl{

      /*商品列表*/
      public function goods_listOp(){
          $goods_model = Model('goods');
          if($_GET['gc_id']){
                 $gc_id = $_GET['gc_id'];
          }else{
                 $gc_id = 0;
          }
          $page = $_GET['page']?$_GET['page']:1;
          $sli = ($page-1)*10;
          if(!$_GET['gc_id']){
              $sql = "select * from 33hao_goods WHERE goods_state=1 AND goods_verify=1 AND goods_cate!=6 limit $sli,10";
          }else {
              $sql = "select * from 33hao_goods WHERE goods_state=1 AND goods_verify=1 AND goods_cate!=6 AND gc_id=" . $gc_id . " limit $sli,10";
          }
          $goods_info = Model()->query($sql);
          // 获取顶级分类
          foreach($goods_info as $k=>$v){
              $goods_info[$k]['imageUrl'] = thumb($v);
          }
          if(!empty($goods_info)) {
              output_data($goods_info);
          }else{
              output_data(0);
          }
      }

      /**
       * 获取商品分类
       */
      public function getClassOp(){
          $g_c_model = Model('goods_class');
          // 获取顶级分类
          $condotion_gc['gc_parent_id'] = $_GET['gc_parentid'];
          $condotion_gc['isshow'] = 1;
          $g_c_info = $g_c_model->getGoodsClassList($condotion_gc);
          output_data($g_c_info);
      }

      /**
       * 添加自选商品到店铺
       */
      public function addGoodstoStoreOp(){
          $id = $_POST['id'];
          $goods_model= model('goods');
          $where['member_id'] = $this->member_info['member_id'];
          $store_info = Model('store')->getStoreInfo($where);
          // 判断商品是否存在
          $goods = $goods_model->getGoodsInfo(array('goods_id'=>$id));
          // 判断本店是否已经自选
          $my_goods = Model('my_store')->where(array('goods_id'=>$id,'store_id'=>$store_info['store_id']))->select();
          if($goods && empty($my_goods)){
              $data['goods_id'] = $id;
              $data['store_id'] = $store_info['store_id'];
              $res = Model('my_store')->insert($data);
              if($res){
                     $array = array(
                         'code'=>200,
                         "msg" => "添加成功",
                     );
              }else{
                     $array = array(
                      'code'=>400,
                      "msg" => "添加失败,请稍后再试……",
                     );
              }
          }else{
              $array = array(
                  'code'=>401,
                  "msg" => "已经添加或商品不存在",
              );
          }
          output_data($array);
      }
  }
?>